﻿using CommunityToolkit.Mvvm.Input;
using MG.SmartHMI.Common;
using MG.SmartHMI.Domain;
using MG.SmartHMI.Entity.DAO;
using MG.SmartHMI.Model.Common;
using MG.Util;
using MG.Util.Log;

namespace MG.SmartHMI.Model
{
    public partial class ButtonViewModel : BaseItemsControl
    {
        public ButtonViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonViewModel() : base()
        {
        }

        #region Button

        [RelayCommand]
        private void BtnTrigger()
        {
            Task.Run(async () =>
            {
                if (RegisterData.DataType.Equals(EnumDataType.BOOL))
                {
                    await ModbusCtrl.Instance.WriteByTrigger(RegisterData.Address, RegisterData.TriggerType);
                    EventBus.Default.Log(new LogInfo($"写入 [{RegisterData.Address}]  {RegisterData.TriggerType.GetDescrip()}"));
                }
                else
                {
                    ModbusCtrl.Instance.UnitWrite(RegisterData.DataType, RegisterData.Address, RegisterData.EffectValue.ToString());
                    EventBus.Default.Log(new LogInfo($"写入 [{RegisterData.Address}]  值 [{RegisterData.EffectValue}]"));
                }
            });
        }

        #endregion Button
    }

    public class ButtonNormViewModel : ButtonViewModel
    {
        public ButtonNormViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonNormViewModel() : base()
        {
        }
    }

    public class ButtonStartViewModel : ButtonViewModel
    {
        public ButtonStartViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonStartViewModel() : base()
        {
        }
    }

    public class ButtonPauseViewModel : ButtonViewModel
    {
        public ButtonPauseViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonPauseViewModel() : base()
        {
        }
    }

    public class ButtonEmgViewModel : ButtonViewModel
    {
        public ButtonEmgViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonEmgViewModel() : base()
        {
        }
    }

    public class ButtonResetViewModel : ButtonViewModel
    {
        public ButtonResetViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonResetViewModel() : base()
        {
        }
    }

    public class ButtonStopViewModel : ButtonViewModel
    {
        public ButtonStopViewModel(RegisterConfig data) : base(data)
        {
        }

        public ButtonStopViewModel() : base()
        {
        }
    }
}